<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends CI_Controller {
	
	function __construct(){
		parent::__construct();
	}
	
	public function index(){
		$this->load->library('phone');
		$res = $this->phone->send('13751053916','VIVIQINSURI');
		echo $res; exit;	
	}
	
	function sms(){
		$pwd = md5('bouyan@c1655');
		$url = "http://116.204.66.74:8080/ema/http/SendSms";
		echo "<form id=\"frm\" action=\"http://116.204.66.74:8080/ema/http/SendSms\" method=\"post\">";
		echo "<input name=\"Account\" value=\"admin\">";
		echo "<input name=\"Password\" value=\"{$pwd}\">";
		echo "<input name=\"SubCode\" value=\"\">";
		echo "<input name=\"Phone\" value=\"15820416527\">";
		echo "<input name=\"Content\" value=\"test\">";
		echo "<input name=\"Wappushurl\" value=\"\">";
		echo "<input name=\"SendTime\" value=\"\">";
		echo "</form>";
		echo "<script>document.getElementById(\"frm\").submit();</script>";
		//http://www.gsdai3.com/test/sms.html
		
		
//		$http = 'http://116.204.66.74:8080/ema/http/SendSms';
//		//$content = str_replace("@", "", $content);
//		$content = 'test';
//		$mob = '15820416527';
//		$time = time();
//		$data = array
//		(
//				'enterpriseID'=>"15606",
//				'loginName'=>"admin",
//				'password'=>strtolower(md5("bouyan@c1655")),
//				'smsId'=>"",
//				'subPort'=>"",
//				'Phone'=>"",
//				'mobiles'=>$mob,
//				'content'=>$content,
//				'sendTime'=>$time
//		);
//		//$ret = $this->do_post($http, $data);
//		
//		$ch = curl_init();
//		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//		curl_setopt($ch, CURLOPT_POST, TRUE);
//		curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
//		curl_setopt($ch, CURLOPT_URL, $url);
//		$ret = curl_exec($ch);
//	
//		curl_close($ch);
//		//return $ret;
//		
//		$xml = simplexml_load_string($ret);
//		if($xml->Result != 0){
//			LOG::write(dump($xml, false, null, false));
//		}
//		var_dump($xml);
	}
	
	public function chebiao(){
		echo intval(5000.01);
//		$this->load->model('Mydb_model','mydb');
//		$this->load->model('Account_model');
//		$this->load->model('Borrow_model');
//		$this->load->model('Message_model');
//		$id=3577;
//		$borrow 		= $this->Borrow_model->get_borrow_obj($id);
//		$borrow_url 	= "<a href='/borrow/slobj/{$id}.html' target=_blank>{$borrow['title']}</a>";
//		
//		$sql = "select * from zjy_borrow_tender where borrow_id={$id}";
//		$tender_list = $this->mydb->query_sql($sql,'list');
//		foreach ($tender_list as $tender){
//			//echo $val['id'],"<br>";
//			if ($tender['user_id']==4373){
//				//var_dump($tender);
//				$mode = $tender['user_id']%100;
//				$user_account = $this->Account_model->get_account($tender['user_id']);
//				$log['user_id'] 	= $tender['user_id'];
//				$log['ftype'] 		= INVEST_FALSE;
//				$log['money'] 		= $tender['account'];
//				$log['total'] 		= $user_account['total'];
//				$log['use_money'] 	= $user_account['use_money']+$log['money'];
//				$log['no_use_money']= $user_account['no_use_money']-$log['money'];
//				$log['collection'] 	= $user_account['collection'];
//				$log['to_user'] 	= $borrow['user_id'];
//				$log['remark'] 		= "投标[{$borrow_url}]失败返回的投标额";
//				$log['add_time'] 	= time();
//				$log['addip'] 		= '127.0.0.1';
//				$this->mydb->add('zjy_account_log_'.$mode, $log);
//				$this->mydb->query_sql("update zjy_account set use_money=use_money+{$log['money']},no_use_money=no_use_money-{$log['money']} where user_id={$tender['user_id']}","set");
////				if($tender['jiaoyan'] != 1){
////					 $this->db->query("update zjy_borrow_tender set jiaoyan=1 where borrow_id={$id} and id={$tender['id']}");
////				}
//				$this->mydb->query_sql("update zjy_borrow_collection set fstatus=2 where tender_id={$tender['id']}","set");
//				$this->mydb->query_sql("update zjy_borrow_tender set fstatus=2 where id={$tender['id']}","set");
//				//提醒设置
//				$this->Message_model->send(array('sent_user'=>1,'receive_user'=>$tender['user_id'],
//											'name'=>"投资的标[<font color=red>{$borrow['title']}</font>]审核失败",
//											'fstatus'=>0,'message_type'=>'system','sented'=>0,'deltype'=>0,
//											'content'=>"你所投资的标[<a href='/borrow/slobj/{$id}.html' target=_blank><font color=red>{$borrow['title']}</font></a>]在".date("Y-m-d",time())."审核失败,失败原因：入口错误",
//											'add_time'=>time(),'addip'=>'127.0.0.1'));
//				
//				$this->mydb->query_sql("update zjy_borrow set account_yes=account_yes-{$tender['account']},tender_times=tender_times-1 where id={$id}");
//				echo 'ok';
//			}
//			
//		}
	}
	
	public function addcredit(){
		$this->load->model('Credit_model');
		
		$credit_value = 960;
		$user_id = 14450;
		
		//增加积分
		$creditNidType = $this->Credit_model->arrays('creditNidType');
		$creditTypeName = $this->Credit_model->arrays('creditTypeName');
		$credit_log = array('user_id'=>$user_id,
							'type_id'=>$creditNidType['invest_success'],
							'op'=>1,
							'credit_value'=>$credit_value,
							'remark'=>$creditTypeName[$creditNidType['invest_success']].'加'.$credit_value.'分',
							'op_user'=>1,
							'add_time'=>time(),
							'addip'=>$this->input->ip_address()
		);
		$this->Credit_model->incr_credit($credit_log);	
	}
	
	
	public function regmoneycheck(){
		$this->load->model('Mydb_model','mydb');
		$start = strtotime('2014-03-14');
		$end = strtotime('2014-04-01');
		$sql = "select user_id from zjy_user where add_time>={$start} and add_time<{$end}";
		$list = $this->mydb->query_sql($sql,'list');
		$total = 0;
		foreach ($list as $val){
			$user_id = $val['user_id'];
			$sql = "select user_id,total,use_money,no_use_money,collection from zjy_account_log where user_id={$user_id} and add_time>={$start} and add_time<{$end} order by id desc limit 1";
			$row = $this->mydb->query_sql($sql,'row');
			if ($row['total']!=0&&($row['total']-$row['use_money']-$row['no_use_money']-$row['collection'])!=0){
				echo $user_id;
				echo "===";
				echo $row['total']," ， ",$row['use_money']," ， ",$row['no_use_money']," ， ",$row['collection']," 。 ";
				echo $row['total']-$row['use_money']-$row['no_use_money']-$row['collection'];
				echo "<br>";
				$total = $total + 1;
			}
		}
		echo "<hr>";
		echo $total;
	}
	
	public function delcache($user_id=0){
		if ($user_id>0){
			$this->load->model('User_model', 'user');
			$this->user->update(array('lasttime'=>time()-3600*24*9),array('user_id'=>$user_id));
			$key = 'zjy_user_'.$user_id;
			$this->mycache->delete($key);
			echo "ok";
		}
		//$key = 'zjy_user_7243';
	}
	
	public function delcachekey(){
		$key="box_specific";
		$this->mycache->delete($key);
		echo "ok";
	}
	
	public function useregmoney(){
		//$this->load->model('Borrow_model');
		//$this->Borrow_model->reg_money_use(array('user_id'=>13514));
	}
	
	public function delvipcache($user_id=0){
		if ($user_id>0){
			$key = 'zjy_user_vip_' . $user_id;
			
//			$info = $this->mycache->get_array($key);
//			echo date('Y-m-d',$info['vip_verify_time']);
//			echo "<br>";
			$setArr = array(
				'vip_verify_time' => strtotime('2014-04-22'),
				'vip_money' => 0,
			);
			$this->load->model('User_vip_model');
			$this->User_vip_model->update($setArr,array('user_id'=>$user_id));
			$info = $this->User_vip_model->get_by_uid($user_id);
			echo date('Y-m-d',$info['vip_verify_time']);
			exit;
			
			echo "ok";
		}
	}
	
	function showkey(){
		$protocolMailKey = "protocolMailKey";
		$mailList = $this->mycache->get_array($protocolMailKey);
		var_dump($mailList);
	}
	
	function addvip(){
		$this->load->model('User_model');
		$this->load->model('User_vip_model');
		//$user = $this->User_model->get_by_uid($user_id);
		$user_id = 2633;
		$vipinfo = $this->User_vip_model->get_by_uid($user_id);
		echo date('Y-m-d',$vipinfo['vip_verify_time']);
		exit;
		$vipSetArr = array(
			'vip_money' => 0,
			'vip_verify_time' => $vipinfo['vip_verify_time']+ 3600*24*365
		);
		$this->User_vip_model->update($vipSetArr,array('user_id'=>$user_id));
	}
	
	public function shopvip(){
		/*
		$this->load->model('User_vip_model', 'vip');
		$user_id = 4625;
		$row = $this->vip->get_by_uid($user_id);
		if ($row && $row['vip_status']==1 && $row['vip_verify_time'] > $time-3600*24*365){
			$setArr = array(
				'vip_verify_time'=>$row['vip_verify_time']+3600*24*365
			);
			$res = $this->vip->update($setArr,array('user_id'=>$user_id));
			var_dump($res);
		}else{
			if ($row){
				$setArr = array(
					'user_id' => $user_id,
					'vip_status' => 1,
					'vip_money' => 0,
					'vip_verify_remark' => 'VIP审核通过',
					'vip_verify_time' => time(),
				);
				$res = $this->vip->update($setArr,array('user_id'=>$user_id));
				var_dump($res);
			}else{
				$this->load->model('User_model');
				$kefuList = $this->User_model->get_kefu_list();
				$kefu_userid = array_rand($kefuList);//随机
				$setArr = array(
					'user_id' => $user_id,
					'kefu_userid' => $kefu_userid,
					'kefu_addtime' => time(),
					'vip_status' => 1,//自动通过无需人工审核
					'vip_remark' => '',
					'vip_money' => 0,//已交费188
					'vip_verify_remark' => 'VIP审核通过',
					'vip_verify_time' => time(),
				);
				$res = $this->vip->apply($setArr);
			}
		}
		*/
	}
	
	function ckvip($user_id=0){
		$user_id=intval($user_id);
		$this->load->model('User_vip_model', 'vip');
		$this->vip->check_vip($user_id);
	}
	
	public function clear(){
		/*$this->load->model('Mydb_model','mydb');
		$sql = "DELETE FROM zjy_borrow";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_borrow_auto";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_borrow_collection";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_borrow_repayment";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_borrow_tender";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_account";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_account_bank";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_account_cash";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_account_log";
		$this->mydb->query_sql($sql,'del');
		$sql = "DELETE FROM zjy_account_recharge";
		$this->mydb->query_sql($sql,'del');
		for ($i=0;$i<100;$i++){
			$sql = "DELETE FROM zjy_account_log_".$i;
			$this->mydb->query_sql($sql,'del');
		}
		*/
	}
	
	function dis(){
		$this->load->model('Discuz_model');
		$data['epage']=8;
		$list = $this->Discuz_model->zuixin($data);
		var_dump($list);
	}
	
	function data_down(){
		/*$filename = date('YmdHis')."_mybackup.sql";
		$tmpFile = (dirname(dirname(dirname(__FILE__))))."\/backup\/".$filename; 
		exec("mysqldump -uroot -pgsda1.mysql1 --default-character-set=utf8 new_gsdai > ".$tmpFile);
		echo "数据已备份至：".(dirname(dirname(dirname(__FILE__))))."/backup/".$filename;
		*/
	}
	
	function update_borrowauto_validendtime(){
		$this->load->model('Borrow_model');
		$vdata = $this->Borrow_model->get_borrow_auto_list();
		foreach ($vdata['borrow_auto_list'] as $val){
			if($val['valid_end_time']>0 && $val['valid_start_time']>0){
				$endtime = strtotime(date('Y-m-d',$val['valid_end_time']).' 23:59:59');
				$data['valid_end_time'] =$endtime;
				$this->Borrow_model->update_borrow_auto($val['id'],$data);
			}
			
		}
		echo 'OK';
	}
	
	function testapi(){
		/*$client = new SoapClient(null,array('location' =>"http://www.gsdai.com/api/bidServer.php",'uri' => "http://127.0.0.1/"));
		$ret = $client->login('wdzjuname','wdzjpwd');//272f08164893f31b677a3548acad3300
		$ret = $client->getSuccessBidInfo('272f08164893f31b677a3548acad3300','2014-06-09');
		$ret = json_decode($ret,true);
		foreach ($ret as $v){
			echo $v['ProjectId'],"----",urldecode($v['Title']),"----",$v['Amount'],"<br>";
		}
		echo "<hr>";*/
		
	}
	
}